#include "PhysicsObject.h"
#include "MathUtility.h"
#include "Timer.h"

namespace Engine
{
	PhysicsObject::PhysicsObject():m_maxSpeed(0.0f),
									   m_maxSpeedSquared(0.0f),
									   m_maxAngularAcc(0.0f),
									   m_maxAngularVel(0.0f),
									   m_maxAcc(0.0f),
									   m_rot(0.0f){}

	void PhysicsObject::Update()
	{
		if(m_steeringOutput.linear.SquaredLength() > m_maxSpeedSquared)
		{
			m_steeringOutput.linear.Normalize();
			m_steeringOutput.linear *= m_maxSpeed;
		}
		
		m_steeringOutput.angular = m_steeringOutput.angular > m_maxAngularAcc ? 
                                   m_maxAngularAcc : m_steeringOutput.angular;

		Vec3 oldVel = m_vel;
		m_vel = m_steeringOutput.linear;

		//update the position
		float dt = TheTimer::Instance() ->GetDT();
		m_pos += (oldVel + m_vel) * .05f * dt;
		m_rot += m_steeringOutput.angular * dt;

		m_steeringOutput.Reset();
	}
}